Skip to content


tag  jupyter  tips  ai  deep learning  beginner  regression  reinforcement learning  q learning  gym  gymnasium  ardupilot  None  ros2  dds  micro ros  xrce  sitl  plugin  gazebo  garden  SITL  debug  rangefinder  pymavlink  mavros  distance sensor  system_time  timesync  cmake  gtest  ctest  101  cpp  c++  format  fmt  multithreading  spdlog  cyclonedds  eprosima  fastdds  aptly  apt  repository  repo  local  mirror  encryption  pgp  docker  arm  container  state  networking  network  nvidia  python  app  devcontainer  gui  tutorial  volume  mount  compose  multi-stage  stage  docker compose  git  bundle  submodules  github  hooks  pre-commit  lxd  lxc  x11  profile  vscode  marpit  presentation  marp  markdown  mermaid  mkdocs  video  ffmpeg  gstreamer  cheat-sheet  sdp  v4l2loopback  gi  kml  geo  gis  spatial  gdal  ogr  raster  vector  snippets  cheat Sheet  asyncio  future  click  cli  cupy  numpy  gpu  dev container  deb  debian  package  setup  stdeb  project  hydra  yaml  configuration  matplotlib  3d  subplot  open3d  point cloud  template  black  isort  templates  cookiecutter  docs  project document  docstrings  flake8  linter  git-hook  mypy  unittest  pytest  pylint  from a-z  fixture  scope  logging  pytest.ini  mock  parameterize  enum  flag  iterator  generator  yml  logging config  tuple  namedtuple  typing  annotation  generic  literal  protocol  self  typed dict  typevar  pyzmq  zmq  opencv  msgpack  slam  cartographer  action  namespace  remap  control2  ros2_control  effort  velocity  gdb  qos  plugins  msg  node  zero-copy  shm  algorithm  calibration  diff  pid  dev  colcon  colcon_cd  settings  behavior  py_trees  bt  behavior_trees  blackboard  plot  visualization  debugging  diagnostic  DiagnosticTask  diagnostics  tutorials  gst  math  apm  rat_runtime_monitor  bag  rosbag  rosbags  tools  ros  web  rosbridge  vue  binding  discovery  gazebo-classic  launch  spawn  model  cook  camera  sensors  gps  imu  ray  gazebo_ros_ray_sensor  lidar  ultrsonic  range  ultrasonic  gazebo classic  wrench  odom  gz  sdf  world  vscode tips  gazebogz-sim-joint-position-controller-system  bridge  simulation  ign  ignition  xacro  diff_drive  odometry  joint_state  argument  OpaqueFunction  DeclareLaunchArgument  LaunchConfiguration  tmux  nav  test  rclpy  goal abort  cancel goal  action client  action server  custom messages  executor  MultiThreadedExecutor  SingleThreadedExecutor  param  dynamic-reconfigure  service  client  setup.py  package.xml  parameter  parameters  custom  msgs  executers  pub  sub  rqt  rviz  rviz2  pose  marker  tf2  local_setup  rosdep  package manager  project settings  vcstool  urdf  robot_state_publisher  urdf_to_graphiz  joint  link  zenoh  tags  hands on  webinar  cross-compiler  nano  jetson  arduino  i2c  sensor  mb1202  uart  serial  tfmini  rpi  config  material  workshope  texture  joints  tmuxp  loop device  rootfs  embedded  zah  linux  rm  ubuntu  sudo  sudoers  nopasswd  visudo  udev  key  gpg  sign  commands  update-alternative  dpkg  ip  ss  netstat  snap  deploy  ssh  systemd  socat  udp  tc  mtu  select  robotics  path planning  trajectory  speed  pcl  kalman_filter  kalman  filter  control  code  extensions  remote  json  schema  yocto  poky  qemu  projects  courses to follow  matrix  graphics  rotation  2d  course  vision  drone  quad  uav  design  vrx  buoyancy 

pylint#

Linting is the automated source code checking for programmatic and stylistic errors.
A lint tool is a basic static code analyzer

pylint is default VSCode linter and it enable by default

install#

install
pip install pylint

VSCode#

Settings#

vscode settings
"python.linting.pylintEnabled": true

Extensions#

pylint extension for Visual Studio Code

  • Execute pylint automatically on python file
  • bundle with pylint can changed by settings pylint.path

Control#

control pylint with rules file .pylintrc

pylintrc file location

  • /etc/pylintrc
  • ~/pylintrc
  • <project_path>/pylintrc
create pylintrc
pylint --generate-rcfile > pylintrc

VSCode

VSCode look automaticly for pylintrc at the project root

pylintrc

pre-commit git hook not found the pylintrc file if we prefix it with dot (.pylintrc)

VSCode file mapping

map pylintrc file to ini type

"files.associations": {
    "pylintrc": "ini"
},

Demo#

minimal pylintrc file to disabled checker message

[MASTER]
disable=
    C0114, # (missing-module-docstring)
    C0115,  # (missing-class-docstring)

Demo II#

Add rules inline

  • Add comment to end of line
# pylint: disable=[problem-code]

# pylint: disable=unused-private-member


Run manual#

~/.local/bin/pylint <file full path>
~/.local/bin/pylint --rcfile=<config_file> <file full path>
demo
~/.local/bin/pylint --rcfile pylintrc  pylint_demo.py
************* Module pylint_demo
pylint_demo.py:2:4: R0201: Method could be a function (no-self-use)
pylint_demo.py:1:0: R0903: Too few public methods (1/2) (too-few-public-methods)

git hook#

  • Install pre-commit python util
  • Add .pre-commit-config.yaml
  • Run pre-commit install
  • Add files to stage
  • Run pre-commit run or try commit stage files
install
pip install pre-commit
.pre-commit-config.yaml
repos:
  - repo: local
    hooks:
      - id: pylint
        name: pylint
        entry: pylint
        language: system
        types: [python]
        args: 
            [
            "--rcfile=pylintrc"
            ]

Demo#

 ~/.local/bin/pre-commit run
[WARNING] Unstaged files detected.
[INFO] Stashing unstaged files to /home/user/.cache/pre-commit/patch1681097484-36170.
pylint...................................................................Failed
- hook id: pylint
- exit code: 8

************* Module pylint_demo
linters/pylint_demo.py:1:0: R0903: Too few public methods (1/2) (too-few-public-methods)

-------------------------------------------------------------------
Your code has been rated at 6.67/10 (previous run: 10.00/10, -3.33)



[INFO] Restored changes from /home/user/.cache/pre-commit/patch1681097484-36170.

pylintrc template#

[MASTER]
disable=
    C0114, # (missing-module-docstring)
    C0115, # (missing-class-docstring)
    C0116, # (missing-function-docstring)

[FORMAT]
# Maximum number of characters on a single line.
max-line-length=120

[BASIC]
# Good variable names which should always be accepted, separated by a comma
good-names=x,y

Tips#

line disable#

import config.logging_settings # pylint: disable=unused-import

function scope disable#

def test():
    # Disable all the no-member violations in this function
    # pylint: disable=no-member
    ...
    # pylint: enable=no-member

Tips#

E1101:Module 'pygame' has no 'init' member
"python.linting.pylintArgs": [
    "--extension-pkg-whitelist=extensionname" // comma separated
]

// or

"python.linting.pylintArgs": [
    "--unsafe-load-any-extension=y"
]

Reference#